package com.whq.knowverywell.task;

import android.content.Context;
import android.os.AsyncTask;

import com.whq.knowverywell.business.http.GetStoreSalesDataUtil;
import com.whq.knowverywell.business.http.model.StoreSalseReturn;
import com.whq.knowverywell.util.LogUtil;
import com.whq.knowverywell.util.constant.CfgConstant;
import com.whq.knowverywell.util.constant.ModelConstant;

/**
 * 汇总统计获取数据
 * @author david
 *
 */
public class SummaryTask extends AsyncTask<String, String, StoreSalseReturn> {
    private final static String TAG = SummaryTask.class.getSimpleName();

    private Context context = null;
    private ResultDataListener listener;
    private int durationType;
    
    public SummaryTask(Context context, ResultDataListener listener, int durationType) {
        this.context = context;
        this.listener = listener;
        this.durationType = durationType;
    }
    
    @Override
    protected StoreSalseReturn doInBackground(String... params) {
        if (this.context == null) {
        	return null;
        }
        
        String orderBy = params[0];
        String sinceCode = params[1];
        LogUtil.i(TAG, "orderBy[" + orderBy + "] sinceCode[" + sinceCode + "]");
        
        StoreSalseReturn huizongResult = null;
        switch (durationType) {
		case ModelConstant.DURATION_TYPE_YESTERDAY:
			huizongResult = GetStoreSalesDataUtil.getYesterdayDataList(this.context, orderBy, sinceCode, CfgConstant.PAGE_COUNT);
			break;
		case ModelConstant.DURATION_TYPE_TODAY:
			huizongResult = GetStoreSalesDataUtil.getTodayDataList(this.context, orderBy, sinceCode, CfgConstant.PAGE_COUNT);
			break;
		case ModelConstant.DURATION_TYPE_MONTH:
			huizongResult = GetStoreSalesDataUtil.getCurrentMonthDataList(this.context, orderBy, sinceCode, CfgConstant.PAGE_COUNT);
			break;
		case ModelConstant.DURATION_TYPE_YEAR:
			huizongResult = GetStoreSalesDataUtil.getCurrentYearDataList(this.context, orderBy, sinceCode, CfgConstant.PAGE_COUNT);
			break;
		default:
			break;
		}
        
        return huizongResult;
    }
    
    @Override
    protected void onPostExecute(StoreSalseReturn huizongResult) {
    	this.listener.handleData(huizongResult);
    }
    
    public interface ResultDataListener {
    	public void handleData(StoreSalseReturn huizongResult);
    }
}
